/*
 *  join
 *  joins items in an array
 */

objx.requires("objx.each", "objx.join")
	.requires("objx.append", "objx.join")
	.requires("objx.type", "objx.join");

objx.fn.join = function() {

	var 	obj = this.type("array"),
			output = objx(""), 
			len = this.size(), 
			seps = arguments.length, 
			sep = 0;
	
	obj.each(objx.bind(function(args, item, index){
		
		output.append(item);
		
		if (index < (len - 1)) {
			
			if (args[sep]) {
				output.append(args[sep]);
			}
			
			// reset the separator position
			if (++sep == seps) {
				sep = 0;
			}
			
		}
		
	}, this, arguments));
	
	return output;
	
};

objx.provides("objx.join");